home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 76 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  4.4 KB

  1. Path: fido.asd.sgi.com!austern
  2. From: chase@centerline.com (David Chase)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Throwing an exception from within a si
  5. Date: 19 Jan 1996 09:35:54 PST
  6. Organization: CenterLine Software
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <4doh5o$k04@wcap.centerline.com>
  9. References: <4dltnb$mca@engnews1.Eng.Sun.COM>
  10. Reply-To: chase@centerline.com
  11. NNTP-Posting-Host: isolde.mti.sgi.com
  12. X-Original-Date: 19 Jan 1996 16:34:00 GMT
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBVAwUBMP/WkEy4NqrwXLNJAQGlEgH/ddZX1EVOQWkNyKatwwfpL5s/qycUI3jC
  15.     SQGFg4jfPhzRGvvswNkT85useg8c0NYzcLgB8RZj1nuADw+6qU6SUg==
  16.     =Cu3c
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. In article mca@engnews1.Eng.Sun.COM, clamage@Eng.Sun.COM (Steve Clamage) writes:
  20. > Suppose that function entry and exit are not atomic operations, which is
  21. > the case on all systems supporting C++ that I am aware of. The "critical
  22. > structure" is the stack frame. If asynchronous interrupts can occur, and
  23. > if you are going to require well-defined exception behavior from signal
  24. > handlers, then you must lock the entirety of every function preamble and
  25. > postamble. (You cannot know that an external signal won't occur.) That
  26. > requirement not only slows down function calls, it adds to interrupt
  27. > latency.
  28.  
  29. As near as I can tell, the best way to do this is to slightly enhance a
  30. PC-range-based exception-handling specification.  I was pushing for
  31. this for the Sparc V9 ABI when I worked at Sun, but it was tough
  32. slogging.  I wrote an article for the JCLT a few years ago that
  33. explained how to do exactly what you are talking about on Sparc  (two
  34. issues in mid-1994).  The essential construct is not one that can be
  35. expressed in C++ -- essentially, it is one where the exception handler
  36. is within the guarded range, but the guarded range is written very
  37. carefully (essentially, all the instructions but the last one in the
  38. normal code sequence can be re-run as many times as necessary).  The
  39. handler for any such guarded critical range finishes the range (e.g.,
  40. gets you in or out of the activation record) and then does the normal
  41. dispatch "as if" the exception arrived at a safe place.  Since stack
  42. frame construction typically takes only a few instructions, whereas
  43. exception dispatch takes many more, this will not have a noticeable
  44. effect on the latency of exception delivery.  Locking is not required,
  45. so you don't pay for that, either.  This technique is portable (as far
  46. as I can tell, from a cursory study) to all RISC architectures, and I
  47. suspect it would port to Intel without too much trouble.
  48.  
  49. > What we put in the language standard is binding on all implementations. We
  50. > try to specify things that can be implemented efficiently on any likely
  51. > system. In addition, we try to specify features so that they have no cost
  52. > (or nearly no cost) if you don't use them. IMHO, guarantees about what you
  53. > can do in an asynchronous signal handler don't meet those criteria for
  54. > inclusion in the C++ standard.
  55.  
  56. I think I've just described a way to do this that is efficient on any
  57. likely system, and that has no runtime cost if you don't use it.  You
  58. can read about it in a journal.  It isn't, to my knowledge, patented.
  59. There's an expansion of code and table space, but if you engineer it
  60. right (take a look at how Sun does their PC-ranges for C++ exceptions;
  61. they're completely position-independent, and need not even be paged
  62. in from disk unless an exception is raised) you'll never load it into
  63. memory.
  64.  
  65. An additional stunt is simply to have your exception-handler recognize
  66. standard function pre and post-ambles, or standard phases of activation
  67. record construction, and avoid the need for additional code.  For
  68. instance, it could merely interpret the preamble to the end, then raise
  69. the exception, and that would not cost more than 100 instructions
  70. (figure 20x cost to interpret 5 instructions).  In the case of the
  71. Sparc SvR4 ABI, there's one way to unwind a leaf routine, and another
  72. way to unwind a normal routine.  There's a variety of ways to solve
  73. this problem, depending upon your code size and latency and throughput
  74. constraints.
  75.  
  76. Of course, some of this may seem like magic to some people, but then maybe
  77. those people shouldn't be implementing C++.
  78.  
  79. speaking for myself,
  80.  
  81. David Chase
  82. ---
  83. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  84.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  85.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  86.